package com.yunkazaixian.syntelecom.configuration;

import com.yunkazaixian.syntelecom.mapper.McSimDxMapper;
import com.yunkazaixian.syntelecom.service.RequestQueueService;
import com.yunkazaixian.syntelecom.worker.RequestWorker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AsyncConfig {
    @Bean(name = "myrequestQueueService")
    public RequestQueueService requestQueueService() {
        return new RequestQueueService();
    }

    @Bean
    public RequestWorker requestWorker(RequestQueueService requestQueueService, McSimDxMapper mcSimDxMapper) {
        return new RequestWorker(requestQueueService.getRequestQueue(), mcSimDxMapper);
    }

    @Bean
    public Thread requestWorkerThread(RequestWorker requestWorker) {
        Thread workerThread = new Thread(requestWorker);
        workerThread.start();
        return workerThread;
    }
}
